﻿using System;
using System.Collections.ObjectModel;

using NUnit.Framework;

using OpenQA.Selenium;

namespace mvcForum.Tests.WebUI {

	[TestFixture]
	public class M010_TopicTypes {
		private IWebDriver driver;
		private String forumName;

		#region Initialization and cleanup
		[TestFixtureSetUp]
		public void TestInitialize() {
			driver = TestHelper.GetDriver();

			forumName = Guid.NewGuid().ToString();

			driver.LogOn(Constants.Users.Admin.Email, Constants.Users.Admin.Password);
			driver.CreateForum("Test board", "Category 1", forumName, "", 1);
			driver.SetStandardAccess("Test board", "Category 1", forumName);
			driver.DisableAntiSpam();
			driver.LogOff();
		}

		[TestFixtureTearDown]
		public void TestCleanup() {
			if (driver != null) {
				driver.Close();
			}
		}
		#endregion

		[Test]
		public void TypeSortOrder() {
			driver.LogOn(Constants.Users.Moderator.Email, Constants.Users.Moderator.Password);

			driver.CreateTopic(forumName, "Regular", "This is an regular topic", "bla bla bla");
			driver.CreateTopic(forumName, "Announcement", "This is an announcement", "bla bla bla");
			driver.CreateTopic(forumName,  "Sticky", "This is a sticky", "bla bla bla");

			driver.LogOff();

			driver.GoToForum(forumName);

			ReadOnlyCollection<IWebElement> results = driver.FindElements(By.ClassName("topictitle"));
			Assert.AreEqual(3, results.Count, String.Format("We expected 3 topics, We got {0}", results.Count));

			Assert.AreEqual(true, results[0].Text.Contains("announcement"), "The announcement should be the first, but the first was: " + (results.Count >= 1 ? results[0].Text : ""));
			Assert.AreEqual(true, results[1].Text.Contains("sticky"), "The sticky should be the second, but the second was: " + (results.Count >= 2 ? results[1].Text : ""));
			Assert.AreEqual(true, results[2].Text.Contains("regular"), "The regular topic should the third, but the third was: " + (results.Count >= 3 ? results[2].Text : ""));
		}
	}
}